<%@page import="javax.servlet.http.Cookie"%>
<%@page import="com.szrt.cookie.utils.CookieUtil"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common.jsp" %>

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8">
	<title>Cookie</title>
	<style>
		*{
			font-size: 14px;
			font-family: "微软雅黑";
		}
		
		span{
			color:red;
		}
		
		#xxx{
			color:red;
		}
	</style>
   </head>
  
  <body>
  	Cookie: 
  	<span >
  		<%
  			Cookie c1 =CookieUtil.getCookie(request, "lastTime");
  			Cookie c2 =CookieUtil.getCookie(request, "currentTime");
  			if(c1.getValue().equals(c2.getValue())){
  				response.getWriter().write("您是第一次访问本站");
  			}else{
  				response.getWriter().write("您上一次访问本站的时间是"+c1.getValue());
  			}
  		%>
  	</span>	
  	
  	<span id="xxx">
  	</span>
  </body>
  
  <script>
  
  	  //当服务器把cookie写到客户端之后  服务器不管    通过客户端的JS代码去拿
	  function getCookie(c_name){
		  if (document.cookie.length>0){
		    var c_start=document.cookie.indexOf(c_name + "=")
		    if (c_start!=-1){ 
		      c_start=c_start + c_name.length+1 
		      c_end=document.cookie.indexOf(";",c_start)
		      if (c_end==-1) c_end=document.cookie.length
		      	return unescape(document.cookie.substring(c_start,c_end))
		      } 
		    }
		  return ""
	  }
  
	  var jieguo =getCookie('lastTime');
	  document.getElementById("xxx").textContent=jieguo;
  
  
  </script>
  
</html>
